/*
 * @(#)ContinuousList.java    Jul 25, 2010
 *
 * Copyright 2009 Nyber Shanghai, Inc. All rights reserved.
 */

package com.lab.puzzle;

import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;

/**
 * Class description goes here.
 *
 * @author nickevin@gmail.com
 * @version Jul 25, 2010 3:24:07 PM
 */

public class ContinuousList {

	/**
	 * 判断集合中的数字是否连续.
	 * 
	 * MAX- MIN+ 1= SIZE; 
	 * 
	 */
	public boolean continuous(List<Integer> list) {
		if (list == null || list.size() == 0) {
			throw new IllegalArgumentException("can't be null object or empty.");
		}

		Collections
				.sort(list/*, new Comparator<Integer>() {public int compare(Integer a, Integer b) {return a.compareTo(b);}}*/);

		Set<Integer> set = new TreeSet<Integer>(list);

		Integer max = list.get(list.size() - 1);
		Integer min = list.get(0);

		return max - min + 1 == set.size();
	}
}
